//
//  XueShengXiangQingVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/16.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "XueShengXiangQingVC.h"
#import "XueShengDetailHeaderView.h"
#import "XunShengDetailCell.h"
#import "SYRequestAPI+Teach.h"

@interface XueShengXiangQingVC ()
@property (nonatomic, strong) XueShengDetailHeaderView *headerView;
@property (nonatomic, strong) NSMutableArray *leftNameArray;//左边标题
@property (nonatomic, strong) NSMutableArray *leftNameArrayValue;//左边值
@property (nonatomic, strong) NSMutableArray *rightNameArray;//右边标题
@property (nonatomic, strong) NSMutableArray *rightNameArrayValue;//右边值
@end

@implementation XueShengXiangQingVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (instancetype)initWothStudentID:(NSString *)studentID{
    if ([super init]) {
        _leftNameArray = [NSMutableArray new];
        _leftNameArrayValue = [NSMutableArray new];
        _rightNameArray = [NSMutableArray new];
        _rightNameArrayValue = [NSMutableArray new];
        self.studentID = studentID;
        [_leftNameArray addObjectsFromArray:@[@"学号",@"电话",@"父亲",@"母亲",@"就读小学"]];
        [_rightNameArray addObjectsFromArray:@[@"姓别",@"生日",@"电话",@"电话",@"报名时间"]];
        self.view.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:self.titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.right.equalTo(@0);
            make.top.equalTo(@0);
            make.height.equalTo(@44);
        }];
        
        [_titleLabel addSubview:self.backButton];
        [_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@10);
            make.centerY.equalTo(self.titleLabel.mas_centerY);
            make.width.equalTo(@60);
            make.height.equalTo(@24);
        }];
        [self.view addSubview:self.tableList];
        [_tableList mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@0).offset(529*fh);
            make.centerX.equalTo(self.view.mas_centerX);
            make.bottom.equalTo(@0);
            make.top.equalTo(@44);
        }];
        [self getXueShengXiangQingRerquest];
    }
    return self;
}
- (void)initSubView{
  
}
- (void)initOption{
    
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(618.5,35,62.5,15);
        label.numberOfLines = 0;
        label.textAlignment = 1;
        label.text = @"学生详情";
        label.textColor = TITLECOLOR;
        label.userInteractionEnabled = YES;
        label.font = [UIFont systemFontOfSize:16];
        _titleLabel = label;
    }
    return _titleLabel;
}
- (UIButton *)backButton{
    if (!_backButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@" 返回" forState:UIControlStateNormal];
        [button setTitleColor:[UIColorChange colorwithHexString:@"SELECTEDCOLOR"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"back_color"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:SELECTEDCOLOR forState:0];
        [button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
        button.userInteractionEnabled = YES;
        _backButton = button;
    }
    return _backButton;
}
- (void)back:(UIButton *)sender{
//    [[NSNotificationCenter defaultCenter]postNotificationName:@"XueShengXiangQingShowNotice" object:nil userInfo:@{@"index":@"0",@"status":@"0"}];
    [UIView animateWithDuration:0.5 animations:^{
        self.view.frame = CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
    }completion:^(BOOL finished) {
        [self.view removeFromSuperview];
    }];
}

- (UITableView *)tableList{
    if (!_tableList) {
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0) style:UITableViewStyleGrouped];
        tableView.delegate  =self;
        tableView.dataSource = self;
        tableView.backgroundColor = [UIColor whiteColor];
        [tableView registerClass:[XunShengDetailCell class] forCellReuseIdentifier:@"XunShengDetailCell"];
        _headerView = [[XueShengDetailHeaderView alloc]init];
        _headerView.frame = CGRectMake(0, 0,self.mainw, 400);
        tableView.tableHeaderView = _headerView;
        tableView.showsVerticalScrollIndicator = NO;
        tableView.showsHorizontalScrollIndicator = NO;
        _tableList = tableView;
    }
    return _tableList;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _leftNameArrayValue.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    XunShengDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XunShengDetailCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[XunShengDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"XunShengDetailCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row%2 == 1) {
        cell.backgroundColor = [UIColor whiteColor];
    }else{
        cell.backgroundColor = [UIColorChange colorwithHexString:@"#F8F8F8"];
    }
    
    cell.leftLabel.text = [NSString stringWithFormat:@"%@:%@",_leftNameArray[indexPath.row],_leftNameArrayValue[indexPath.row]];
    cell.rightLabel.text = [NSString stringWithFormat:@"%@:%@",_rightNameArray[indexPath.row],_rightNameArrayValue[indexPath.row]];
    [cell reloadViewLayout];
    return cell;
}
- (void)lookUp:(UIButton *)sender{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"XueShengXiangQingShowNotice" object:nil userInfo:@{@"status":@"1",@"index":[NSString stringWithFormat:@"%d",(int)sender.tag-100]}];
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *mainView = [[UIView alloc]init];
    return mainView;
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"XueShengXiangQingShowNotice" object:nil];
    
}
#pragma mark - 学生详情
- (void)getXueShengXiangQingRerquest{
    NSDictionary *parama = @{@"studentId":self.studentID};
    [MBProgressHUD mj_showMessage:nil toView:self.view];
    [SYRequestAPI sy_getClassServiceClassStudentDetail:parama success:^(id  _Nonnull responseObject) {
        NSLog(@"得到学生详情 %@",responseObject);
        self->_model = [XueShengXiangQingModel yy_modelWithJSON:[responseObject objectForKey:@"data"]];
        [self->_headerView.headerImageView sd_setImageWithURL:[NSURL URLWithString:self->_model.headImg] placeholderImage:[UIImage imageNamed:@"morentouxiang.png"]];
        self->_headerView.nameLabel.text = self->_model.name;
        [self->_leftNameArrayValue addObject:self->_model.serial];
        if ([self->_model.sex isEqualToString:@"1"]) {
            [self->_rightNameArrayValue addObject:@"男"];
        }else if ([self->_model.sex isEqualToString:@"2"]){
            [self->_rightNameArrayValue addObject:@"女"];
        }else{
            [self->_rightNameArrayValue addObject:@"不确定"];
        }
        
        [self->_leftNameArrayValue addObject:self->_model.status];
        [self->_rightNameArrayValue addObject:self->_model.birthday];
        [self->_leftNameArrayValue addObject:self->_model.father];
        [self->_rightNameArrayValue addObject:self->_model.fatherPhone];
        [self->_leftNameArrayValue addObject:self->_model.monther];
        [self->_rightNameArrayValue addObject:self->_model.montherPhone];
        [self->_leftNameArrayValue addObject:self->_model.fulltimeSchool];
        [self->_rightNameArrayValue addObject:self->_model.inDate];
        [self.tableList reloadData];
        [MBProgressHUD mj_hideHUDForView:self.view];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUDForView:self.view];
    }];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
